package cn.edu.scau.cmi.chenyuanying.summary;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.chenyuanying.orm.hibernate.HibernateSessionFactory;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class SummaryController implements Initializable {
	@FXML private Button singleton;
	@FXML private Button multiton;
	@FXML private Button simplyFactory;
	@FXML private Button factory;
	@FXML private Button abstractFactory;
	@FXML private Button classAdapter;
	@FXML private Button objectAdapter;
	@FXML private Button safedComposite;
	@FXML private Button transparentComposite;
	@FXML private Button hibernate;
	@FXML private Button spring;
	
	public void showStage(String path, String title) throws IOException {
		Parent root = FXMLLoader.load(getClass().getResource(path));
		Stage stage = new Stage();
		stage.setTitle(title);
		stage.setScene(new Scene(root));
		if(title.equals("Spring") || title.equals("Hibernate")) {
			stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
				@Override
				public void handle(WindowEvent event) {
					HibernateSessionFactory.getSessionFactory().close();				
				}			
			});
		}
		stage.show();
	}	
	
	public void singletonClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/singleton/singletonStage.fxml", "单例模式");
	}
	public void multitonClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/multiton/multitonStage.fxml", "多例模式");
	}
	public void simplyFactoryClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/simpleFactoryMethod/SimpleFactoryMethodStage.fxml", "简单工厂模式");
	}
	public void factoryClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/factoryMethod/FactoryMethodStage.fxml", "工厂模式");
	}
	public void abstractFactoryClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/abstractFactoryMethod/AbstractFactoryMethodStage.fxml", "抽象工厂模式");
	}
	public void classAdapterClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/classAdapter/ClassAdapterStage.fxml", "类适配器模式");
	}
	public void objectAdapterClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/objectAdapter/ObjectAdapterStage.fxml", "对象适配器模式");
	}
	public void safedCompositeClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/safedComposite/SafedCompositeStage.fxml", "安全组合模式");
	}
	public void transparentCompositeClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/transparentComposite/TransparentCompositeStage.fxml", "一致性组合模式");
	}	
	public void hibernateClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/orm/hibernate/HibernateStage.fxml", "Hibernate");
	}	
	public void springClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/chenyuanying/spring/view/SpringStage.fxml", "Spring");
	}	

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub

	}

}

